import { createApp } from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'vant/lib/index.css'; // 引入Vant组件样式
import './styles/global.css'; // 引入全局自定义样式

//防抖函数
const debounce = (fn: any, delay: any) => {
    let timer: any
    return (...args: any) => {
        if (timer) {
            clearTimeout(timer)
        }
        timer = setTimeout(() => {
            fn(...args)
        }, delay)
    }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback: any) {
        callback = debounce(callback, 200);
        super(callback);
    }
}

//通过app遍历所有的组件 修改配置 进行图标注册
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.use(router).mount('#app')
